package vn.aptech.scrumgroup.model;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.Rect;

public class ToolArcModel extends AbstractBaseModel{
	
	public String header;
	public Point tlPoint;
	public int numLines;
	public int height;
	private float rowSize;
	private float beginCellX;
//	private float beginCellY;
	private int rectWidth;
	private int rectHeight;
	public int offsetX;
	public float strokeWidth;
	
	public ToolArcModel(String header, Point tlPoint, int numLines, int height, int backColor, int foreColor) {
		super(backColor, foreColor);
		// TODO Auto-generated constructor stub
		this.header = header;
		this.numLines = numLines;
		this.tlPoint = tlPoint;
		this.height = height;
		rowSize = height/(numLines);
		beginCellX = tlPoint.x;
//		beginCellY = tlPoint.y;
		offsetX = 2;
	}//end ctor
	
	@Override
	public boolean isPointOf(float x, float y) {
		// TODO Auto-generated method stub
		if (x>tlPoint.x&&x<(tlPoint.x+rectWidth)&&y>tlPoint.y&&y<(tlPoint.y+height)){
			return true;
		}//end if
		return false;
	}//end method

	@Override
	public void changeColor(int color) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onDraw(Canvas c) {
		// TODO Auto-generated method stub
		//draw border
		Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
		paint.setStyle(Style.STROKE);
		//draw header text
		Rect rect = new Rect();
		paint.getTextBounds(header, 0, header.length(), rect);
		rectWidth = rect.width();
		rectHeight = rect.height();
		paint.setColor(backColor);
		c.drawRect(tlPoint.x, tlPoint.y, tlPoint.x+rectWidth+offsetX, tlPoint.y+height, paint);
		
		//draw a line
		c.drawLine(beginCellX, tlPoint.y+rectHeight+4, beginCellX+rectWidth+offsetX, tlPoint.y+rectHeight+4, paint);
//		strokeWidth = paint.getStrokeWidth();
//		paint.setStrokeWidth(strokeWidth/4);
		
		//draw header
		paint.setTextSize(9);
//		paint.setTextSize(DrawUtil.calculateTextSize(header, rectWidth, paint, 3));
		paint.setStrokeWidth(0.8f);
		paint.setColor(foreColor);
		c.drawText(header, tlPoint.x+offsetX, tlPoint.y+rectHeight+2, paint);
		
		//draw number lines
		float y = tlPoint.y+rectHeight+4;
		float oldTextSize = paint.getTextSize();
		paint.setTextSize(oldTextSize/2);
		for (int i = 0; i<numLines-2; i++){
			y += rowSize;
			//c.drawLine(beginCellX, y, beginCellX + rectWidth+offsetX, y, toolPaint);
			c.drawText(""+i+".", beginCellX+offsetX, y, paint);
		}//end for
		paint.setTextSize(oldTextSize);
//		toolPaint.setStrokeWidth(strokeWidth);
	}//end draw

	@Override
	public void onUpdate(double t) {
		// TODO Auto-generated method stub
		
	}

}//end class
